Skip to content

Conversation

xrmx
Copy link
Member

@xrmx xrmx commented Aug 25, 2025

What does this pull request do?

This PR moves to OpenTelemetry 1.35.0 as baseline to move off deprecated log events and use log records directly. The telemetry output does not change.

Related issues

Closes #85

@xrmx xrmx force-pushed the use-logger branch 2 times, most recently from 2d2d8d8 to 1974277 Compare August 27, 2025 13:25
@xrmx xrmx marked this pull request as ready for review August 27, 2025 13:27
@xrmx xrmx requested review from a team as code owners August 27, 2025 13:27
@xrmx
Copy link
Member Author

xrmx commented Aug 27, 2025

@anuraaga Could you please take a look? Should I just remove the beta chat completions instrumentation?

Copy link

@fr4nc1sc0-r4m0n fr4nc1sc0-r4m0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM --> The CI changes

@anuraaga
Copy link
Contributor

@xrmx Personally I would remove the beta chat instrumentation indeed since I think it's superceded by the responses API

@anuraaga
Copy link
Contributor

anuraaga commented Sep 4, 2025

@xrmx Personally I would remove the beta chat instrumentation indeed since I think it's superceded by the responses API

But the current version ceiling looks fine too

@anuraaga
Copy link
Contributor

anuraaga commented Sep 4, 2025

@xrmx Sorry I realized I needed to refresh my venv when testing. Actually I still had an issue when trying it out

  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py", line 113, in export
    return self._export(batch)
           ~~~~~~~~~~~~^^^^^^^
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/grpc/exporter.py", line 316, in _export
    request=self._translate_data(data),
            ~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py", line 110, in _translate_data
    return encode_logs(data)
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py", line 37, in encode_logs
    return ExportLogsServiceRequest(resource_logs=_encode_resource_logs(batch))
                                                  ~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py", line 74, in _encode_resource_logs
    sdk_resource = sdk_log.log_record.resource
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'LogRecord' object has no attribute 'resource'

AFAICT, this is because of open-telemetry/opentelemetry-python#4319

I came up with a workaround to force use the SDK LogRecord - it's a bit too hairy for me to commit directly to this PR so I sent a PR for this PR.

#91

I also had to work around severity_number crash which is probably an easier to fix bug in the logs exporter

  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py", line 113, in export
    return self._export(batch)
           ~~~~~~~~~~~~^^^^^^^
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/grpc/exporter.py", line 316, in _export
    request=self._translate_data(data),
            ~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py", line 110, in _translate_data
    return encode_logs(data)
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py", line 37, in encode_logs
    return ExportLogsServiceRequest(resource_logs=_encode_resource_logs(batch))
                                                  ~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py", line 76, in _encode_resource_logs
    pb2_log = _encode_log(sdk_log)
  File "/Users/anuraag/git/observability-examples/genai-function-calling/openai-agents/.venv/lib/python3.13/site-packages/opentelemetry/exporter/otlp/proto/common/_internal/_log_encoder/__init__.py", line 64, in _encode_log
    severity_number=log_data.log_record.severity_number.value,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'value'

Given the logs SDK doesn't seem to be working well currently, should we hold off on this PR? I recommend splitting off the beta fix, either as the version ceiling or removing the instrumentation, to a separate PR to get it released ASAP to support newer openai versions.

@xrmx
Copy link
Member Author

xrmx commented Sep 9, 2025

@anuraaga I think the ceiling fix is required just for CI and wrapt would just ignore silently stuff that was not able to wrap.

@xrmx
Copy link
Member Author

xrmx commented Sep 19, 2025

@anuraaga rebased and bumped baseline after fixing Logger.emit for API Logrecord upstream.

@xrmx xrmx requested a review from anuraaga September 19, 2025 12:59
@xrmx xrmx closed this Sep 19, 2025
@xrmx xrmx reopened this Sep 19, 2025
@codefromthecrypt
Copy link
Contributor

any chance we can land this before elasticon NYC? (like in a week)? there's some significant tech debt until this is merged and released.

@xrmx
Copy link
Member Author

xrmx commented Oct 1, 2025

any chance we can land this before elasticon NYC? (like in a week)? there's some significant tech debt until this is merged and released.

Yeah, we should be able do that

@xrmx xrmx requested a review from anuraaga October 1, 2025 10:19
@xrmx xrmx merged commit 70d798a into main Oct 1, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

openai: stop using deprecated Event APIs
5 participants